global.Promise = require('bluebird')
const database = require('./libs/database')
const Post = require('./models/post')
const User = require('./models/user');

(async() => {
  try {
    await database.connect()

    let username = 'Mankong'
    let password = 'abc@123'
    let displayName = '赵文强'

    let user = await User.findOne({ username, password })
    user.save()
    let userJson = user.toJSON()
    console.log(userJson)

    // if (!user) {
    //   user = await User.create({ username, password, displayName })
    // }
    // let title = '我是post标题'
    // let content = '我是post内容'
    // let post = await Post.create({ title, content, user })


    /**
     * post读取
     */
    //let posts = await Post.find({}).populate('user')
    //console.log(posts)
  } catch (error) {
    console.log(error)
  }
})()
